package net.wsfcp.android.http.mvp.presenter;

import net.wsfcp.android.base.BasePresenter;
import net.wsfcp.android.http.mvp.contract.FindPasswordContract;
import net.wsfcp.android.http.mvp.model.FindPasswordModel;
import net.wsfcp.android.http.mvp.IModel;
import net.wsfcp.android.ui.view.my.activity.FindPasswordActivity;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

/**
 * Created by Shaoboyang on 2018/12/14.
 */
//找回密码
public class FindPasswordPresenter extends BasePresenter<FindPasswordActivity> implements
        FindPasswordContract.FindPasswordPresenter {
    @Override
    public void findPassword(String name, String mail, String code) {
        if (!getIView().checkNull()) {
            ((FindPasswordModel) getiModelMap().get("findpassword")).findPassword(name, mail, code, new FindPasswordModel
                    .FindPasswordInfoHint() {
                @Override
                public void findPasswordSuccessInfo() {
                    getIView().findPasswordSuccess();
                }

                @Override
                public void findPasswordFailInfo(String str) {
                    getIView().findPasswordFail(str);
                }


            });
        }
    }


    @Override
    public void getImageCode() {
        ((FindPasswordModel) getiModelMap().get("imagecode")).getCode(new FindPasswordModel
                .ImageInfoHint() {

            @Override
            public void getImageCodeSuccessInfo(InputStream inputStream) {

                try {
                    getIView().getImageCodeSuccess(inputStream);  //成功
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void getImageCodeFailInfo(String str) {
                getIView().getImageCodeFail(str);  //失败
            }

        });
    }


    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new FindPasswordModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        map.put("findpassword", models[0]);
        map.put("imagecode", models[0]);
        return map;
    }


}
